let id;

window.onload = function (){
    id = getQuery("id");
    init();
}

function init(){
    axios.get("/product/findById",{params:{id}}).then(resp =>{
        let info = resp.data;
        $("pimg").src = "/productImg/"+info.imgPath;
        $("nameSpan").innerHTML = info.name;
        $("priceSpan").innerHTML = info.price;
        $("speakSpan").innerHTML = info.speakNum;

        let str = "";
        info.speakList.forEach(n =>{
           str += `<tr><td>${n.user.name}</td><td>${n.content}</td></tr>`;
        });
        $("data").innerHTML = str;
    });
}

function addSpeak(){
    axios.get("/speak/add",{
        params: {
            productId:id,
            content:$("content").value
        }
    }).then(resp =>{
        var info = resp.data;
        alert(info);
        if(info == "ok"){
            init();
        }
        else if(info == "noland"){
            location.href = "/login.html?info=noland";
        }
    })
}